package com.weme.common.view.pickerview.adapter;


import com.weme.common.view.pickerview.contrarywind.adapter.WheelAdapter;

/**
 * Numeric Wheel adapter.
 */
public class NumericWheelAdapter implements WheelAdapter {
	
	private int minValue;
	private int maxValue;

	/**
	 * Constructor
	 * @param minValue the wheel min value
	 * @param maxValue the wheel max value
	 */
	public NumericWheelAdapter(int minValue, int maxValue) {
		this.minValue = minValue;
		this.maxValue = maxValue;
	}

	@Override
	public Object getItem(int index) {
		if (index >= 0 && index < getItemsCount()) {
			int value = minValue + index;
			if(maxValue<=12){
				switch (value){
					case 1 :
						return "01";
					case 2 :
						return "02";
					case 3 :
						return "03";
					case 4 :
						return "04";
					case 5 :
						return "05";
					case 6 :
						return "06";
					case 7 :
						return "07";
					case 8 :
						return "08";
					case 9 :
						return "09";
					case 10 :
						return "10";
					case 11 :
						return "11";
					case 12 :
						return "12";

				}
			}

			return value+"";
		}
		return 0;
	}

	@Override
	public int getItemsCount() {
		return maxValue - minValue + 1;
	}
	
	@Override
	public int indexOf(Object o){
		try {
			return (int)o - minValue;
		} catch (Exception e) {
			return -1;
		}

	}
}
